package syn;

import java.util.ArrayList;

/**
 * @author mubei
 * @date 2021/11/20
 * @description
 */
public class UnsafeList {


    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();


        for (int i = 0; i < 100 * 100; i++) {
            // 多个线程 处理了同一个位置
            new Thread(()->{
                synchronized(list){
                    list.add(Thread.currentThread().getName());
                }

            }).start();
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(list.size());
    }
}
